package com.tengju.bff.infrastructure.export.repo;

import com.tengju.bff.infrastructure.export.convert.TableVoConvert;
import com.tengju.bff.interfaces.manage.crm.brand.facade.BrandAnalysisRankFacade;
import com.tengju.bff.interfaces.manage.crm.brand.vo.BrandSaleRankForm;
import com.tengju.bff.interfaces.shared.TableVO;
import com.tengju.bff.interfaces.shared.export.BrandSaleRankExportQuery;
import com.tengju.data.domain.model.user.UserIdCode;
import com.tengju.export.domain.record.ExportDataSourceRepository;
import com.tengju.export.domain.record.Query;
import com.tengju.export.domain.record.Table;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 李大仙
 * @date: 2021/8/23 2:39 下午
 */
@Service("brandSaleRankExportDataSourceRepository")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class BrandSaleRankExportDataSourceRepository implements ExportDataSourceRepository {

    private final BrandAnalysisRankFacade brandAnalysisRankFacade;

    @Override
    public Table batchFindDataSource(Query query) {
        BrandSaleRankExportQuery exportQuery = (BrandSaleRankExportQuery) query;
        BrandSaleRankForm brandSaleRankForm = new BrandSaleRankForm();
        brandSaleRankForm.setPageIndex(exportQuery.getPageIndex());
        brandSaleRankForm.setPageSize(exportQuery.getPageSize());
        brandSaleRankForm.setDateType(exportQuery.getDateType());
        brandSaleRankForm.setCrowdPerspective(exportQuery.getCrowdPerspective());
        brandSaleRankForm.setBelongSecIdCode(exportQuery.getBelongSecIdCode());
        brandSaleRankForm.setBelongEcIdCode(exportQuery.getBelongEcIdCode());
        brandSaleRankForm.setBrandId(exportQuery.getBrandId());
        brandSaleRankForm.setIdCode(exportQuery.getIdCode());
        brandSaleRankForm.setClubId(exportQuery.getClubId());
        brandSaleRankForm.setSaleMoneyFrom(exportQuery.getSaleMoneyFrom());
        brandSaleRankForm.setSaleMoneyTo(exportQuery.getSaleMoneyTo());
        brandSaleRankForm.setDirect(exportQuery.isDirect());
        brandSaleRankForm.setOrderColumn(exportQuery.getOrderColumn());
        brandSaleRankForm.setOrderType(exportQuery.getOrderType());
        List<UserIdCode> dataGenSecIdCodes = exportQuery.getDataGenSecIdCodes();
        TableVO tableVO = brandAnalysisRankFacade.brandSaleRank(brandSaleRankForm, dataGenSecIdCodes);
        return TableVoConvert.convert(tableVO);
    }
}
